package com.zy.modules.oss.service.impl;

import com.zy.modules.oss.dao.OssRepository;
import com.zy.modules.oss.entity.SysOssEntity;
import com.zy.modules.oss.service.SysOssService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("sysOssService")
public class SysOssServiceImpl implements SysOssService {
    @Resource
    private OssRepository ossRepository;

    @Override
    public SysOssEntity queryObject(Long id) {
        return ossRepository.findOne(id);
    }

    @Override
    public List<SysOssEntity> queryList(Map<String, Object> map) {
        int limit = (int) map.getOrDefault("limit", 10);
        int offset = (int) map.getOrDefault("offset", 0);
        Pageable pageable = new PageRequest(offset, limit);
        Page<SysOssEntity> entities = ossRepository.findAll(pageable);
        return entities.getContent();
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return (int) ossRepository.count();
    }

    @Override
    public void save(SysOssEntity sysOss) {
        ossRepository.save(sysOss);
    }

    @Override
    public void update(SysOssEntity sysOss) {
        ossRepository.save(sysOss);
    }

    @Override
    public void delete(Long id) {
        ossRepository.delete(id);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            ossRepository.delete(id);
        }
    }

}
